package com.zhitxx.base.ui

import android.content.Intent
import android.os.Build
import android.os.Bundle
import android.view.View
import androidx.databinding.DataBindingUtil
import androidx.databinding.ViewDataBinding
import androidx.lifecycle.ViewModel
import com.zhitxx.base.viewmodel.BaseViewModel
import com.zhitxx.common.utils.LogUtils

abstract class MvvmActivity<VB : ViewDataBinding, VM : BaseViewModel> : BaseActivity() {

    protected lateinit var mBinder: VB
    protected lateinit var mMainModel: VM

    abstract fun requestLayout(): Int
    abstract fun requestViewModel(): VM
    abstract fun initView(savedInstanceState: Bundle?)

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        mBinder = DataBindingUtil.setContentView(this, requestLayout())
        mMainModel = requestViewModel()
        initView(savedInstanceState)
    }


    private fun setLightStatusBar(light: Boolean) {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
            var ui = window.decorView.systemUiVisibility
            when (light) {
                true -> {
                    ui = View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR or ui
                }
                false -> {
                    ui = View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR.inv() and ui
                }
            }
            window.decorView.systemUiVisibility = ui
        }
    }

}